<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: DatabaseLoader</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">DatabaseLoader</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/etl/stdload_rb.html">
                etl/stdload.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="ETL.html">
                ETL
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This class loads DTO objects into a relational database. It can be used
within an <a href="ETL.html">ETL</a> process only during the <b><a
href="DatabaseLoader.html#M000018">load</a></b> phase. The class operates
in insert_update mode, creating resources (pages, sources, words) whenever
needed.
</p>
<p>
Database configuration must be defined within the <a
href="ETL.html">ETL</a> properties. The following keys are recognized:
</p>
<ul>
<li>host: the hostname where the database is

</li>
<li>user: the username to use for the connection

</li>
<li>pass: the password to use for the connection

</li>
<li>db: the database to connect to

</li>
</ul>
<p>
An additional property is supported: <tt>strategy</tt> . This property is
optional. If present, it must define the name of a class which will provide
the word <a href="DatabaseLoader.html#M000018">load</a> strategy. A
strategy collects the logic to properly analyze a <a
href="WordDTO.html">WordDTO</a> and translate it into the proper database
operations. The class must implement the method
<tt>insert(source_id,page_id,scantime,word)</tt> .
</p>
<p>
The default strategy is <a
href="SimpleWordStrategy.html">SimpleWordStrategy</a> .
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000025">get_page_id</a>&nbsp;&nbsp;
      <a href="#M000023">get_source_id</a>&nbsp;&nbsp;
      <a href="#M000021">get_strategy</a>&nbsp;&nbsp;
      <a href="#M000020">insert_word</a>&nbsp;&nbsp;
      <a href="#M000019">insert_words</a>&nbsp;&nbsp;
      <a href="#M000018">load</a>&nbsp;&nbsp;
      <a href="#M000024">with_page</a>&nbsp;&nbsp;
      <a href="#M000022">with_source</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Log.html">Log</a></span>
        <span class="include-name"><a href="DatabaseHelper.html">DatabaseHelper</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000025" class="method-detail">
        <a name="M000025"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000025.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000025.html');return false;">
          <span class="method-name">get_page_id</span><span class="method-args">(dto,source_id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the id of the page defined in the dto. The page is created and a
new id is assigned to it if needed.
</p>
        </div>
      </div>

      <div id="method-M000023" class="method-detail">
        <a name="M000023"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000023.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000023.html');return false;">
          <span class="method-name">get_source_id</span><span class="method-args">(dto)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the id of the source defined in the dto. The source is created and
a new id is assigned to it if needed.
</p>
        </div>
      </div>

      <div id="method-M000021" class="method-detail">
        <a name="M000021"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000021.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000021.html');return false;">
          <span class="method-name">get_strategy</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the strategy that will be used to insert words into the database.
</p>
        </div>
      </div>

      <div id="method-M000020" class="method-detail">
        <a name="M000020"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000020.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000020.html');return false;">
          <span class="method-name">insert_word</span><span class="method-args">(strategy,source_id,page_id,scantime,word)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Inserts a single <a href="WordDTO.html">WordDTO</a> into the database,
using the provided <tt>strategy</tt>
</p>
        </div>
      </div>

      <div id="method-M000019" class="method-detail">
        <a name="M000019"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000019.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000019.html');return false;">
          <span class="method-name">insert_words</span><span class="method-args">(source_id,page_id,dto)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Insert all the words contained in the <tt>dto</tt> into the database.
</p>
        </div>
      </div>

      <div id="method-M000018" class="method-detail">
        <a name="M000018"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000018.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000018.html');return false;">
          <span class="method-name">load</span><span class="method-args">(dto,context)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
loads the dto passed as parameter into a MySQL database
</p>
        </div>
      </div>

      <div id="method-M000024" class="method-detail">
        <a name="M000024"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000024.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000024.html');return false;">
          <span class="method-name">with_page</span><span class="method-args">(dto,source_id) {|page_id| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Invokes the block passed as parameter within the context of the page
defined in the dto. The page is created if yet missing from the database
</p>
        </div>
      </div>

      <div id="method-M000022" class="method-detail">
        <a name="M000022"></a>

        <div class="method-heading">
          <a href="DatabaseLoader.src/M000022.html" target="Code" class="method-signature"
            onclick="popupCode('DatabaseLoader.src/M000022.html');return false;">
          <span class="method-name">with_source</span><span class="method-args">(dto) {|source_id| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Invokes the block passed as parameter within the context of the source
defined in the dto. The source is created if yet missing from the database
</p>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>